package com.adamfass.tractorbeam;

import com.jme.bounding.OrientedBoundingBox;
import com.jme.math.FastMath;
import com.jme.math.Matrix3f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;
import com.jmex.physics.PhysicsSpace;

// TODO(afass): Does this even need to be a game entity?
public class BoxObstacle extends StaticPhysicsGameObject {
  private final Box box;
  
  public BoxObstacle(Node rootNode, PhysicsSpace physicsSpace, Vector3f position, 
      float xExtent, float yExtent, ColorRGBA color, String name) {
    super(physicsSpace);
    
    physicsNode.createBox(name);
    rootNode.attachChild(physicsNode);
    
    box = new Box(name, new Vector3f(), 0.5f, 0.5f, 1);
    final MaterialState materialState =
      DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
    materialState.setEnabled(true);
    materialState.setDiffuse(color);
    materialState.setAmbient(color);
    box.setRenderState(materialState);
    box.updateRenderState();
    physicsNode.attachChild(box);
    
    physicsNode.setLocalScale(new Vector3f(xExtent, yExtent, 1));
    physicsNode.setLocalTranslation(position);
    
    physicsNode.updateGeometricState(0, true);
    physicsNode.setModelBound(new OrientedBoundingBox());
    physicsNode.updateModelBound();
  }
  
  public void beforeUpdate() {
  }
  
  public void update() {
  }
}
